package me.shurufa.holder;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.Bind;
import butterknife.ButterKnife;
import me.shurufa.R;
import me.shurufa.activities.UserInfoActivity;
import me.shurufa.model.Book;
import me.shurufa.model.User;
import me.shurufa.utils.Constants;
import me.shurufa.utils.Utils;
import me.shurufa.widget.CircleImageView;

/**
 * 发现页用户列表
 *
 * @FileName: me.shurufa.holder.DiscoverUserHolder.java
 * @author: kHRYSTAL
 * @email: 723526676@qq.com
 * @date: 2016-01-21 23:33
 */
public class DiscoverUserHolder extends BaseViewHolder{

    @Bind(R.id.user_avatar)
    CircleImageView userAvatar;
    @Bind(R.id.user_nick)
    TextView userNick;

    private Context mContext;
    private User mUser;

    public DiscoverUserHolder(View itemView, Object parent) {
        super(itemView, parent);
        mContext = itemView.getContext();
        ButterKnife.bind(this, itemView);
        addOnClickListener(userAvatar);
        addOnClickListener(userNick);
    }

    public void bind(User user){
        if (user == null)
            return;
        mUser = user;
        if (!TextUtils.isEmpty(user.nickname))
            userNick.setText(user.nickname);
        if (!TextUtils.isEmpty(user.avatar)){
            Glide.with(mContext).load(user.avatar).into(userAvatar);
        }else {
            //TODO 设置默认图片
            userAvatar.setImageResource(R.drawable.default_avatar);
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.user_nick:
            case R.id.user_avatar:
                Intent intent = new Intent(mContext, UserInfoActivity.class);
                intent.putExtra(Constants.EXTRA_USER_PARAM,mUser.toString());
                mContext.startActivity(intent);
                break;
        }
    }
}
